//
//  GRGoodWebHtmlCell.m
//  YC_GRice
//
//  Created by luojinrong11 on 2019/4/17.
//  Copyright © 2019 YeCai. All rights reserved.
//

#import "GRGoodWebHtmlCell.h"

@implementation GRGoodWebHtmlCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
  
    self.goodWebView.delegate = self;
    self.goodWebView.scrollView.scrollEnabled = NO;
}

-(void)setIntro:(NSString *)intro{
    _intro = intro;
    
    if (intro) {
        
        NSString *html = [NSString stringWithFormat:@"<html> \n"
                          "<head> \n"
                          "<style type=\"text/css\"> \n"
                          "body {font-size:15px;}\n"
                          "</style> \n"
                          "</head> \n"
                          "<body>"
                          "<script type='text/javascript'>"
                          "window.onload = function(){\n"
                          "var $img = document.getElementsByTagName('img');\n"
                          "for(var p in  $img){\n"
                          "$img[p].style.width = '100%%';\n"
                          "$img[p].style.height ='auto'\n"
                          "}\n"
                          "}"
                          "</script>%@"
                          "</body>"
                          "</html>",intro];
        
        [self.goodWebView loadHTMLString:[NSString stringWithFormat:@"<meta content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;\" name=\"viewport\" />%@<div id=\"testDiv\"></div>", html] baseURL:nil];
        
          
    }
}


-(void)webViewDidFinishLoad:(UIWebView *)webView{
    
    CGFloat height = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"] floatValue];
    if (_delegate && [_delegate respondsToSelector:@selector(reloadWebViewHeight:)]) {
        [_delegate reloadWebViewHeight:height];
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
